from typing import List
from heapq import *

class Solution:
    def minRefuelStops(self, target: int, startFuel: int, stations: List[List[int]]) -> int:
        '''
        大顶堆
        '''
        cur, q, ans = startFuel, [], 0
        for pos,fuel in stations + [[target,0]]:                
            while cur < pos:
                if not q:return -1
                cur += - heappop(q)
                ans += 1
            heappush(q,-fuel)
        return ans
